package com.wxgo.controller.admin;

import java.util.List;

import com.jfinal.core.Controller;
import com.wxgo.common.model.Industry;
import com.wxgo.common.model.Role;
import com.wxgo.consts.NewsConsts;
import com.wxgo.factory.DaoFactory;

public class IndustryController extends Controller {

	public void manage() {
		List<Industry> industryList = DaoFactory.industryDao().find("select * from industry where type=0");
		setAttr("tableList", industryList);
		render("/admin/industry/industryManage.html");
	}

	public void add() {
		List<Role> roleList = DaoFactory.roleDao().findAll();
		setAttr("roleList", roleList);
		render("/admin/industry/industryAdd.html");
	}

	public void save() {
		Industry industry = getModel(Industry.class, "industry");
		industry.save();
		manage();
		return;
	}

	public void delete() {
		String id = getPara("id");
		if ("1".equals(id)) {
			manage();
			return;
		}
		DaoFactory.industryDao().delete("industry", id);
		manage();
	}

	public void edit() {
		Integer id = getParaToInt("id");
		Industry industry = DaoFactory.industryDao().findById(id);
		setAttr("industry", industry);
		render("/admin/industry/industryEdit.html");
	}

	public void company() {
		Industry industry = DaoFactory.industryDao().findByType(NewsConsts.COMPANY);
		setAttr("industry", industry);
		render("/admin/aboutus/aboutusEdit.html");
	}

	public void service() {
		Industry industry = DaoFactory.industryDao().findByType(NewsConsts.SERVICE);
		setAttr("industry", industry);
		render("/admin/aboutus/aboutusEdit.html");
	}

	public void aboutus() {
		Industry industry = DaoFactory.industryDao().findByType(NewsConsts.ABOUTUS);
		setAttr("industry", industry);
		render("/admin/aboutus/aboutusEdit.html");
	}

	public void concactus() {
		Industry industry = DaoFactory.industryDao().findByType(NewsConsts.CONCACTUS);
		setAttr("industry", industry);
		render("/admin/aboutus/aboutusEdit.html");
	}

	public void joinus() {
		Industry industry = DaoFactory.industryDao().findByType(NewsConsts.JOINUS);
		setAttr("industry", industry);
		render("/admin/aboutus/aboutusEdit.html");
	}

	public void update() {
		Industry industry = getModel(Industry.class, "industry");
		int type = industry.getType();
		boolean flag = industry.update();
		String url = null;
		if (type == NewsConsts.DEFAULT) {
			manage();
			return;
		} else {
			setAttr("industry", industry);
			if (flag) {
				setAttr("msg", "保存完毕!");
			} else {
				setAttr("msg", "保存失败!");
			}
			url = "/admin/aboutus/aboutusEdit.html";
		}
		render(url);
	}
}
